<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link rel="stylesheet" type="text/css" href="../css/common.css?01_38" />
		<link rel="stylesheet" type="text/css" href="../css/templet.css?01_38" />
		<link rel="stylesheet" type="text/css" href="../fonts/font-awesome.min.css?01_38" />
		<link rel="stylesheet" type="text/css" href="../mui/css/mui.css?01_38" />

		<!--公共js-->
		<script type="text/javascript" src="../common/js/jquery.js?01_38"></script>
		
		<!--插件-->
		<script type="text/javascript" src="../common/js/vue.min.js?01_38"></script>
		<script type="text/javascript" src="../common/js/mui.min.js?01_38"></script>
		
		<script type="text/javascript" src="../common/js/fastclick.js?01_38"></script>
		<script type="text/javascript" src="../common/js/common.js?01_38"></script>
		<script type="text/javascript" src="../common/js/my_common.js?01_38"></script>
		<script type="text/javascript" src="../common/js/main.js?01_38"></script>
		<script type="text/javascript" src="../common/js/app.js?01_38"></script>
	</head>

	<body>
		<div class="wrap_body my_shop discount_coupon" id="app" v-cloak="">

			<header class="f-20 pad-t-10 pad-b-10 pad-r-10">
				<div class="pa back" style="padding-left: 10px;" @click="backpre()">
					<a></a>
				</div>
			</header>

			<div class="mask bg-000 pa loading" v-if="curStatus != 1">
				<div class="pad-l-40 pad-r-40 pad-t-200">
					<div class="bg-fff wrap pr center ">
						<img src="../images/default_graph/animation.gif" />
					</div>
				</div>
			</div>
			<div class="pad-t-45" @dblclick="freshPage" v-else="">
				<div class="content pad-l-10 pad-r-10">
					<p class="fff f-27 center mag-t-30">{{b_lg[1210]}}</p>

					<!--服务员状态码为2时，店铺绑定申请中；服务员状态码为4时，店铺绑定申请被拒绝；-->
					<template v-if="waiter_status == 2||waiter_status == 4">
						<div class="audit">
							<div class="item bg-fff  mag-t-30 pad-l-15 pad-r-15 pad-t-20 pad-b-20">
								<dl class="fiex">
									<dt class="mag-r-15">
										<img v-if=" shop_logo!='' " id="image" :src="oss+shop_logo" class="icon"/>
										<img v-else id="image" alt="上传头像" :src="con_img" class="icon" onerror="lod(this)"/>
									</dt>
									<dd class="pad-t-5 fiex1">
										<!--店铺名-->
										<p class="f-18 f-b">{{shop_name}}</p>
										<!--店铺地址-->
										<p class="f-13 ellipsis-2">{{address}}</p>

									</dd>
								</dl>
								<div class="center"><img src="../images/default_graph/wait.png" / class="clock"></div>

								<!--申请结果-->
								<div class="center f-13">{{txt}}</div>
								<p class="mag-t-10 reapply">
									<a class="fff btn btn_red pad-l-30 pad-r-30 pad-t-15 pad-b-15 f-15 bk center bg-red9" @click="reapply">{{b_lg[1240]}}</a>
								</p>
							</div>
						</div>
					</template>

					<!--服务员状态码为1时，店铺已绑定-->
					<template v-else-if="waiter_status == 1">
						<!--上班-->

						<div class="item scan_work bg-fff  mag-t-30 pad-l-15 pad-r-15 pad-t-20 pad-b-20 p-b-60">
							<dl class="fiex">
								<dt class="mag-r-15">
										<img v-if=" shop_logo!='' " id="image" :src="oss+shop_logo" class="icon"/>
										<img v-else id="image" alt="上传头像" :src="con_img" class="icon" onerror="lod(this)"/></dt>
								<dd class="fiex1 pad-t-5 fiex">
									<div class="fiex5 pad-r-10">
										<!--店铺名-->
										<p class="f-18 f-b">{{shop_name}}</p>
										<!--店铺地址-->
										<p class="f-13 ellipsis-2">{{address}}</p>
									</div>
									<div class="red9 f-13 fiex1" @click="leaveshop">{{b_lg[1241]}}</div>

								</dd>
							</dl>

							<div>
								<div>
									<!--未上班-->
									<div v-if="status == 0">
										<!--扫码上班-->
										<div v-if="is_open_scan_work == 1">
											<a class="bk center red9 f-15 mag-t-35 mag-b-25 btn btn_red pad-t-15 pad-b-15" @click="scan_work">{{b_lg[1242]}}</a>
										</div>
										<!--点击按钮上班-->
										<div v-else-if="is_open_scan_work == 0">
											<a class="bk bg-red9 fff btn_red btn pad-l-50 pad-r-50 pad-t-15 pad-b-15 center btn" @click="startWork">{{b_lg[1243]}}</a>

										</div>

									</div>

									<!--已上班-->
									<div v-else-if="status == 1">
										
										<div class="center red9 f-30 f-b pad-t-30">{{work_time}}</div>
										<div class="center pad-b-15">{{b_lg[1214]}}</div>
										<!--<div>
											<a class="bk bg-red9 fff btn_red btn pad-l-50 pad-r-50 pad-t-15 pad-b-15 center" @click="endWork">{{b_lg[1215]}}</a>

										</div>-->
										<!--扫码上班-->
										<div v-if="is_open_scan_work == 1">
											<a class="bk center red9 f-15 mag-t-35 mag-b-25 btn btn_red pad-t-15 pad-b-15" @click="scan_work">{{b_lg[1387]}}</a>
										</div>
										<!--点击按钮上班-->
										<div v-else-if="is_open_scan_work == 0">
											<a class="bk bg-red9 fff btn_red btn pad-l-50 pad-r-50 pad-t-15 pad-b-15 center btn" @click="startWork">{{b_lg[1243]}}</a>

										</div>
									</div>

									<!--已下班-->
									<div v-else-if="status == 2" class="pad-t-10">
										<!--扫码上班-->
										<div v-if="is_open_scan_work == 1">
											<a class="bk center red9 f-15 mag-t-35 mag-b-25 btn btn_red pad-t-15 pad-b-15" @click="scan_work">{{b_lg[1242]}}</a>
										</div>
										<!--点击按钮上班-->
										<div v-else-if="is_open_scan_work == 0">
											<a class="bk bg-red9 fff btn_red btn pad-l-50 pad-r-50 pad-t-15 pad-b-15 center btn" @click="startWork">{{b_lg[1243]}}</a>

										</div>
									</div>

								</div>

								<p class="mag-t-15">
									<a class="bk blue btn pad-l-50 pad-r-50 pad-t-15 pad-b-15 center record_btn" @click="gotoart('attendanceRecord.html')">{{b_lg[1246]}}</a>
								</p>
							</div>

						</div>
					</template>

					<!--服务员状态码为3时，店铺解绑中-->
					<template v-else-if="waiter_status == 3">
						<!--没有店铺-->
						<div class="without_shop">

							<div class="bg-fff pad-l-15 pad-r-15 pad-t-30 pad-b-40 text mag-t-15">
								<div class="center">
									<h2>{{b_lg[1247]}}</h2>
									<h4 class="red9 pad-t-15">{{b_lg[1248]}}</h4>
									<div class="line-ccc"></div>
									<div class="f-15">{{b_lg[1249]}}</div>
								</div>
								<!--搜索部分-->
								<!--<div class="top bg-red9 pad-l-10 pad-r-10 pad-t-25">-->
								<!--<p class="fff f-24">加入店铺</p>-->
								<div class="bg-fff fiex pad-r-20 search mag-b-30">
									<div class="fiex1">
										<input type="search" placeholder="输入店铺码" class="pad-t-15 pad-b-15 pad-l-12 pad-r-12 bk col-sm-11 f-24" v-model="numbercode" />
									</div>
									<div @click="bindShop" class="pad-l-5">
										<div class="scan"></div>
									</div>
								</div>
								<div class="center pad-t-20 pad-b-10" @click="bind">
									<a class="bg-red9 fff pad-l-70 pad-r-70 pad-t-15 pad-b-15 btn f-16">立即加入</a>
								</div>
								<!--</div>-->
								<div class="">
									<div class="item cf mag-t-25">
										<div class="number fl f-15">1</div>
										<div class="mag-l-35 c666">{{b_lg[1250]}}</div>
									</div>
									<div class="item cf mag-t-30">
										<div class="number fl f-15">2</div>
										<p class="mag-l-35 c666">{{b_lg[1251]}}</p>
									</div>
									<div class="item cf mag-t-30">
										<div class="number fl f-15">3</div>
										<p class="mag-l-35 c666">{{b_lg[1252]}}</p>
									</div>
								</div>
							</div>
							<div class="bank30"></div>
							<!--<p>
								<div class="fff f-15">
									<p class="scan_code"></p>
									<p class="pad-b-30 fff center">{{b_lg[1253]}}</p>
								</div>
							</p>	-->
						</div>
					</template>

				</div>

			</div>

		</div>
	</body>

	<script type="text/javascript">
		var app = null;
		//下拉刷新
		function refresh() {
			app.init();
			console.log("刷新刷新")
		}
		var getScan = getQueryString("scan");
		if(getScan == 1) {
			setTimeout(function() {
				app.gotoart("../qrcode/qrscan.html?id=0&type=2")
			}, 300)
		}
		var l = window.localStorage.getItem("lg");
		console.log(l);
		console.log($("a .record_btn"));
		if(l == "en") {
			$(".record_btn").css({
				"padding-left": "5px"
			})
		}
		//用于其他页面返回调用--设置上个页面返回值\
		function back_index(t) {
			if(t == 1) { //语言切换返回

			} else if(t == 2) { //绑定店铺
				var shopSn = localStorage.getItem("shopSn")
				common_ajax(1, {
					shop_sn: shopSn
				}, "put_waiter_bind_shop", function(res) {
					if(res.status == 1) { //请求成功
						app.init();
						localStorage.removeItem("shopSn");
					} else {
						mui.toast(res.msg);
					}
				})
			} else if(t == 3) { //上下班签到扫码
				common_ajax(1, {
					uuid: phone_uuid
				}, "put_work_sign_scan", function(res) {
					if(res.status == 1) { //请求成功
						app.init();
					} else {
						mui.toast(res.msg);
					}
				})
			}
		}
		var getLeave = getQueryString("leave");
		//id为1时，是从会员卡记录进来的
		//id为2时，是从扫码页进来的
		function plusReady() {}
		if(window.plus) {
			plusReady();
		} else {
			document.addEventListener('plusready', plusReady, false);
		}

		// 关闭自身窗口
		function closeme() {
			var ws = plus.webview.currentWebview();

			plus.webview.close(ws);
		}
		// 关闭父层窗口
		function closepre() {
			var preUrl = plus.webview.currentWebview().opener();
			var ws = plus.webview.currentWebview();

			plus.webview.close(ws);
			plus.webview.close(preUrl);
		}
		//		back_index(2);
		function fun1() {
			down_load()
			
			window.addEventListener('touchmove', function() {
				var h = $(this).scrollTop();
				//				var header = document.querySelector("header");
				if(h > 1) {
					$("header").css("backgroundColor", "#fd5749");
				} else {
					$("header").css("backgroundColor", "transparent");
				}
			})

			//创建vue
			app = new Vue({
				el: "#app",
				data: {
					icon: "",
					shop_name: "",
					address: "",
					txt: "",
					sn: "",
					shop_logo: "",
					shop_id: "",
					scount: 0,
					work_time: "",
					waiter_status: "",
					msg: {},
					time: "",
					addtime: "",
					endtime: "",
					status: "", //上班状态
					b_lg: global_lange, //语言包
					is_open_scan_work: "",
					curStatus: "",
					numbercode: ""//店铺码
				},
				created: function() {
					this.init();
				},
				methods: {
					gotoart: function(e) { //跳转地址
						clicked(e); //全局
					},
					//初始化
					init: function() {

						common_ajax(1, {}, "get_shop_info", function(res) { //获取店铺信息
							//判断是否请求成功
							if(res.status == 1) {
								var data = res.result;
								app.curStatus = res.status;
								if(data.waiter_status == 1) {
									common_ajax(1, {}, "get_home", function(res) {
										app.status = res.result.check_work.status;
										app.address = res.result.shop_info.shop_address;
										app.time = res.result.time;
										app.addtime = res.result.check_work.addtime;
										app.is_open_scan_work = res.result.shop_info.is_open_scan_work;
										console.log("app.is_open_scan_work:"+app.is_open_scan_work)
										console.log("app.status:"+app.status)
										console.log(res)
										console.log(app.addtime + "我是打卡时间")
										console.log(app.time + "我是当前时间")
										console.log(app.status + "打卡状态");
										console.log(app.waiter_status + "服务员状态");
										console.log(phone_uuid + "我是uuid")
										console.log(getItem("is_success_scan"));
										if((typeof app.time) !== Object && (typeof app.addtime) !== Object) {
											//时间格式化
											var h = parseInt((res.result.time - res.result.check_work.addtime) / 3600);
											var m = parseInt((res.result.time - res.result.check_work.addtime) / 60 % 60)
											app.work_time = (h >= 10 ? h : ('0' + h)) + ":" + (m >= 10 ? m : ('0' + m)); //计算工作时长
										}
									})
								} else if(data.waiter_status == 2) {
									app.txt = "等待审核……";
								} else if(data.waiter_status == 4) {
									app.txt = "审核失败";

								}

								app.shop_name = res.result.shop_name;
								app.shop_logo = res.result.shop_logo;
								app.shop_id = res.result.shop_id;
								app.waiter_status = res.result.waiter_status;
								console.log(res.result);
							} else {
								mui.toast(res.msg);
							}
						})

					},
					//扫码绑定店铺
					bindShop: function() {
						setTimeout(function() {
							app.gotoart("../qrcode/qrscan.html?id=0&type=2");
						}, 500)
					},
					//输入店铺码绑定店铺
					bind: function() {
						//提示框
						if(app.numbercode == "") {
							mui.toast("请输入店铺码！")
						} else if(app.numbercode.length != 8) {
							mui.toast("请输入完整的店铺码！")
						} else {
							var btnArray2 = [app.b_lg[1049], app.b_lg[1008]];
							mui.confirm(app.b_lg[1262], app.b_lg[1050], btnArray2, function(ee) {
								if(ee.index == 1) {
									//确定
									common_ajax(1, {
										shop_sn: app.numbercode
									}, "put_waiter_bind_shop", function(res) {
										if(res.status == 1) { //请求成功
											app.init();

										} else {
											mui.toast(res.msg);
										}
										app.numbercode = "";
									})
								} else {
									//取消
									app.init();
								}
							},"div")
						}

					},
					//解绑店铺
					leaveshop: function() {
						//提示框
						var btnArray2 = [app.b_lg[1049], app.b_lg[1008]];
						mui.confirm(app.b_lg[1263], app.b_lg[1050], btnArray2, function(ee) {
							if(ee.index == 1) {
								//确定
								common_ajax(1, {}, "put_waiter_unbind_shop", function(res) {
									//判断数据是否请求成功
									if(res.status == 1) { //请求成功
										//跳转到扫码页
										app.waiter_status = 3; //改变服务员状态
									} else { //请求失败
										mui.toast(res.msg);
									}
								})
							} else {
								//取消
								app.init();
							}
						},"div")
					},
					//点击按钮上班开始计时
					startWork: function() {

						//提示框
						var btnArray2 = [app.b_lg[1049], app.b_lg[1008]];
						mui.confirm(app.b_lg[1264], app.b_lg[1050], btnArray2, function(ee) {
							if(ee.index == 1) {
								//确定
								console.log(phone_uuid);
								common_ajax(1, {
									uuid: phone_uuid
								}, "put_work_sign_scan", function(res) {
									//判断数据是否请求成功
									console.log(res);
									if(res.status == 1) { //请求成功
										//										app.init();
										//										app.gotoart("../work/workbench.html");
										//										console.log(app.status+"打卡状态")
										//										console.log("上班了")
										if(isAPP) {
											var preUrl = plus.webview.currentWebview().opener();
											preUrl.evalJS('refresh()');
											preUrl.evalJS('bank_btn(1)');

										}
										setTimeout(function() {
											com_back();
										}, 500);

									} else { //请求失败
										mui.toast(res.msg);
									}
								})
							} else {
								//取消
								app.init();
							}
						},"div")
					},

					//扫描二维码上班开始计时
					scan_work: function() {

						//跳转到扫码页
						setTimeout(function() {
							app.gotoart('../qrcode/qrscan.html?id=0&type=4&scan=0'); //上下班type=4
						}, 500)

					},
//					//扫描二维码下班
//					scan_end: function() {
//						common_ajax(1, {
//							uuid: phone_uuid
//						}, "put_work_sign_scan", function(res) {
//							//判断数据是否请求成功
//							if(res.status == 1) { //请求成功
//								//跳转到扫码页
//								setTimeout(function() {
//									app.gotoart('../qrcode/qrscan.html?id=0&type=4'); //上下班type=4
//								}, 500)
//							} else { //请求失败
//								mui.toast(res.msg);
//							}
//						})
//					},
					//下班结束计时
					endWork: function() {
						//提示框
						var btnArray2 = [app.b_lg[1049], app.b_lg[1008]];
						mui.confirm(app.b_lg[1265], app.b_lg[1050], btnArray2, function(ee) {
							if(ee.index == 1) {
								//确定
								common_ajax(1, {
									uuid: phone_uuid
								}, "put_work_sign_scan", function(res) {
									//判断数据是否请求成功
									if(res.status == 1) { //请求成功
										app.init();
										var preUrl = plus.webview.currentWebview().opener();
										preUrl.evalJS('refresh()');
										console.log(app.status + "打卡状态")
										console.log("下班了")
									} else { //请求失败
										mui.toast(res.msg);
									}
								})
							} else {
								//取消
								app.init();
							}
						},"div")
					},
					//重新申请绑定店铺
					reapply: function() {

						//提示框
						var btnArray2 = [app.b_lg[1049], app.b_lg[1008]];
						mui.confirm(app.b_lg[1266], app.b_lg[1050], btnArray2, function(ee) {
							if(ee.index == 1) {
								//queding
								common_ajax(1, {
									uuid: phone_uuid
								}, "put_waiter_unbind_shop", function(res) {
									//判断数据是否请求成功
									if(res.status == 1) { //请求成功
										//										app.waiter_status = 3;//改变服务员状态
										setTimeout(function() {
											app.gotoart('../qrcode/qrscan.html?id=0&type=2'); //绑定店铺type=2
										}, 500)
										console.log(app.status)
									} else { //请求失败
										mui.toast(res.msg);
									}
								})
							} else {
								//取消
								app.init();
							}
						},"div")
					},
					freshPage: function() {
						console.log("我是双击");
						//						this.init();
					},
					backpre: function() {
						var a;
						if(getLeave == "work") {
							a = 1;
						} else {
							a = 2;
						}
						if(isAPP) {
							var preUrl = plus.webview.currentWebview().opener();
							preUrl.evalJS('refresh()');
							preUrl.evalJS('bank_btn(' + a + ')');
						}
						setTimeout(function() {
							com_back();
						}, 500)
					}
				}
			});
			if(isAPP) {
				mui.back = function() {}
				var a = ""
				if(getLeave == "work") {
					a = 1;
				} else {
					a = 2;
				}
				And_back('myShop2', a)
			}
			app.shop_name = JSON.parse(getItem("shop_name"));
		}
	</script>

</html>
